//: CashInOutForm.java 05.09.2008 10:07:34Z apt $
package com.devunion.salon.web.form;

import com.devunion.salon.web.bean.CashInOutBean;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Timoshenko Alexander
 */
public class CashInOutForm extends ActionForm {
    private String hiddenDate;

    private String cashIn;
    private String cashOut;
    private String cashInNotes;
    private String cashOutNotes;
    private String submittedValue;

    private List<CashInOutBean> caches = new ArrayList<CashInOutBean>();

    public void reset(ActionMapping mapping, HttpServletRequest request) {
        cashIn = cashOut = cashInNotes = cashOutNotes = submittedValue = null;
        caches.clear();
        super.reset(mapping, request);
    }

    public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
        ActionErrors errors = new ActionErrors(); 
        if(StringUtils.isBlank(cashIn) && StringUtils.isBlank(cashOut)){
            errors.add(Globals.ERROR_KEY, new ActionMessage("errors.correct.cach"));
        }

        if(!StringUtils.isBlank(cashIn) && !NumberUtils.isNumber(cashIn)){
            errors.add(Globals.ERROR_KEY, new ActionMessage("errors.number", cashIn));
        }

        if(!StringUtils.isBlank(cashOut) && !NumberUtils.isNumber(cashOut)){
            errors.add(Globals.ERROR_KEY, new ActionMessage("errors.number", cashOut));
        }

        return errors;
    }

    public String getCashIn() {
        return cashIn;
    }

    public void setCashIn(String cashIn) {
        this.cashIn = cashIn;
    }

    public String getCashOut() {
        return cashOut;
    }

    public void setCashOut(String cashOut) {
        this.cashOut = cashOut;
    }

    public String getCashInNotes() {
        return cashInNotes;
    }

    public void setCashInNotes(String cashInNotes) {
        this.cashInNotes = cashInNotes;
    }

    public String getCashOutNotes() {
        return cashOutNotes;
    }

    public void setCashOutNotes(String cashOutNotes) {
        this.cashOutNotes = cashOutNotes;
    }

    public String getSubmittedValue() {
        return submittedValue;
    }

    public void setSubmittedValue(String submittedValue) {
        this.submittedValue = submittedValue;
    }

    public List<CashInOutBean> getCaches() {
        return caches;
    }

    public void setCaches(List<CashInOutBean> caches) {
        this.caches = caches;
    }

    public String getHiddenDate() {
        return hiddenDate;
    }

    public void setHiddenDate(String hiddenDate) {
        this.hiddenDate = hiddenDate;
    }
}
